/********************************************************************
* Name: X86CodeGenerator.h: 
*
* Description:
*   Generate X86 code with X86Code abstract structure
*   of X86binary.
*   
*
* History:
*   Create: gxf. 2008-12-15
*   Rev. 1: gxf. 2009-03-28
*
********************************************************************/
#ifndef X86_CODE_GENERATOR_H
#define X86_CODE_GENERATOR_H

#include "crossbit/Translator.h"
#include "arch/x86/X86AsmGenerator.h"
#include "arch/x86/X86AsmOptimizer.h"
#include "arch/x86/X86BinGenerator.h"

namespace crossbit{

class X86CodeGenerator: public Translator {
    public:
        X86CodeGenerator(ProcessorState *state):
            _asmGen(NULL), _asmOpt(NULL), _binGen(NULL),
		    src_state(state)
        {}

    public:
        void encode(VBlock *vblock, TBlock *tblock){
            AsmBlock* asmBlock = _asmGen -> GenPseudoAsm(vblock);
            _asmOpt -> ApplyOpt(&asmBlock);
            _binGen -> GenBinary(&asmBlock, tblock);
        }

    protected:
        X86AsmGenerator* _asmGen;
        X86AsmOptimizer* _asmOpt;
        X86BinGenerator* _binGen;

};

}// namespace crossbit

#endif

